-- <nowiki>
local T = {
    -- 函数, 用于抛出异常
    error = require('Dev:User error'),
    -- error = function(message)
    --     print(message)
    -- end,
    -- 处理并复制参数
    parseArgs = function(argsRaw)
        if argsRaw.args ~= nil then
            argsRaw = argsRaw.args
        end

        local args = {}
        for k, v in pairs(argsRaw) do
            if v ~= '' then
                args[k] = v
            end
        end

        return args
    end,
    -- 处理异常数据的还在那时
    parseErrorValue = function(value)
        return '[' .. tostring(value) .. ', ' .. type(value) .. ']'
    end,
    -- 根据分隔符转换为数组表
    split = function(value, sep)
        local indexSep = 1
        local indexTable = 1

        local tableSplit = {}

        while true do
            local indexFind = string.find(value, sep, indexSep, true)

            if not indexFind then
                -- if indexSep < string.len(value) then
                tableSplit[indexTable] = string.sub(value, indexSep, string.len(value))
                -- end

                break
            end

            tableSplit[indexTable] = string.sub(value, indexSep, indexFind - 1)
            indexTable = indexTable + 1

            indexSep = indexFind + string.len(sep)
        end

        return tableSplit
    end
}
-- 根据路径读取数据
T.getter = function(target, arrKey)
    if type(arrKey) == 'string' then
        return T.getter(target, T.split(arrKey, '.'))
    end

    if type(arrKey) ~= 'table' then
        return T.error('[Tool.getter.arrKey]' .. T.parseErrorValue(arrKey) .. ' is not Table')
    end

    if type(target) ~= 'table' then
        return T.error('[Tool.getter.target]' .. T.parseErrorValue(target) .. ' is not Table')
    end

    local now = target
    local parts = ''
    for _, key in pairs(arrKey) do
        if type(key) ~= 'string' then
            return T.error('[Tool.getter.arrKey.key]' .. T.parseErrorValue(arrKey) .. ' is not String')
        end

        if now == nil then
            return now
        elseif type(now) ~= 'table' then
            return T.error(
                '[Tool.getter.target' .. parts .. ']' .. T.parseErrorValue(now) .. ' is neither Nil nor Table'
            )
        end

        parts = parts .. '.' .. key
        now = now[key]
    end

    return now
end

return T
-- </nowiki>
-- [[Category:Module]][[Category:Module/Function]]
